use strict;
use warnings;
use Data::Dumper;
use Test::More 'no_plan';
use Bio::Rambam::Proteomics::MzML;
use Bio::Rambam::Proteomics::Mgf;
use File::Temp qw/tempdir/;


my $mzml_file			=	"./testdata/test.mzML";
my $mzml_file_noindex	=	"./testdata/test_noindex.mzML";
my $mgf_file			=	"./testdata/test.mgf";
my  $output_folder  = tempdir( CLEANUP => 1 );
my  $output_folder2 = tempdir( CLEANUP => 1 );

my $mzml1=Bio::Rambam::Proteomics::MzML->new(file=>$mzml_file);
my $mzml2=Bio::Rambam::Proteomics::MzML->new(file=>$mzml_file_noindex);

is($mzml1->filename(),	"test.mzML",		"Test1: Indexed mzML filename parsing correct");
is($mzml2->filename(),	"test_noindex.mzML","Test2: No-Indexed mzML filename parsing correct");
is($mzml1->version(),	"1.1.1", 			"Test3: Indexed mzML correct version: 1.1.1");
is($mzml2->version(),	"1.1.0", 			"Test4: No-Indexed mzML correct version: 1.1.0");
ok(mgf_from_mzML(139027),					"Test5: mgf file created from mzml in $output_folder: Filesize: 139027 bytes");
ok(ms2_from_mzML(137357),					"Test6: ms2 file created from mzml in $output_folder: Filesize: 137357 bytes");
 
my $mgf=Bio::Rambam::Proteomics::Mgf->new(file=>$mgf_file);
ok(ms2_from_mgf(137357), "Test7: ms2 file created from mgf  in $output_folder2: Filesize: 137357 bytes");


sub mgf_from_mzML{
	$mzml1->create_mgf(output_folder=>$output_folder);
	return 1 if -s $output_folder."/test.mgf"==$_[0];
}
sub ms2_from_mzML{
	$mzml1->create_ms2(output_folder=>$output_folder);
	return 1 if -s $output_folder."/test.ms2"==$_[0];
}
sub ms2_from_mgf{
	$mgf->convert_to_ms2(output_folder=>$output_folder2);
	return 1 if -s $output_folder2."/test.ms2"==$_[0];
}
